package com.financing.platform.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.financing.platform.dao.IUserInfoDao;
import com.financing.platform.dto.UserInfoDTO;
import com.financing.platform.util.SqlName;
import com.financing.platform.vo.LicashiCountVO;
import com.financing.platform.vo.LicashiDetailVO;

@Repository("userInfoDaoImpl")
public class UserInfoDaoImpl extends BaseDaoImpl implements IUserInfoDao{

	public UserInfoDTO queryUserInfo(UserInfoDTO userInfoDTO) {
		try {
			return (UserInfoDTO) this.sqlMapClient.queryForObject(SqlName.queryUserInfo,userInfoDTO);
		} catch (SQLException e) {
			log.error("User login error:",e);
			return null;
		}
	}

	public UserInfoDTO addUserInfo(UserInfoDTO userInfoDTO) {
		try {
			userInfoDTO.setUserId((String)this.sqlMapClient.queryForObject(SqlName.queryUUID));
			this.sqlMapClient.insert(SqlName.addUserInfo, userInfoDTO);
		} catch (SQLException e) {
			log.error("Add userInfo error:",e);
			return null;
		}
		return userInfoDTO;
	}

	public UserInfoDTO updateUserInfo(UserInfoDTO userInfoDTO) {
		try {
			this.sqlMapClient.update(SqlName.updateUserInfo, userInfoDTO);
		} catch (SQLException e) {
			this.log.error("Update userInfo error:",e);
			return null;
		}
		return userInfoDTO;
	}

	@SuppressWarnings("unchecked")
	public List<UserInfoDTO> queryAllUserInfo(UserInfoDTO userInfoDTO) {
		try {
			return (List<UserInfoDTO>)this.sqlMapClient.queryForList(SqlName.queryUserInfo,userInfoDTO);
		} catch (SQLException e) {
			this.log.error("Query all userInfo error:",e);
			return null;
		}
	}

	@Override
	public List<LicashiCountVO> querylcsstatistics(Map<String,String> map) throws SQLException {
		return (List<LicashiCountVO>)this.sqlMapClient.queryForList(SqlName.querylcsstatistics,map);
	}

	@Override
	public Map<String, String> querymanstatistics(Map<String,String> map) throws SQLException {
		return this.sqlMapClient.queryForMap(SqlName.querymanstatistics, map, "telephone", "sysCount");
	}

	@Override
	public List<LicashiDetailVO> querylcsDetailstatistics(Map<String, String> map)
			throws SQLException {
		return (List<LicashiDetailVO>)this.sqlMapClient.queryForList(SqlName.querylcsDetailstatistics,map);
	}

	@Override
	public int countlcsDetailstatistics(Map<String, String> map)
			throws SQLException {
		return (Integer) this.sqlMapClient.queryForObject(SqlName.countlcsDetailstatistics,map);
	}

	@Override
	public List<String> queryUserInfoSubUserId(String systemUserId)
			throws SQLException {
		return (List<String>)this.sqlMapClient.queryForList(SqlName.queryUserInfoSubUserId,systemUserId);
	}

	@Override
	public List<Map<String, Object>> queryVistDetail(Map<String, Object> map) throws SQLException {
		return this.sqlMapClient.queryForList(SqlName.queryVistDetail,map);
	}

	@Override
	public Map<String,String> queryUserPhoneByManagerLCS(
			Map<String, Object> map) throws SQLException {
		return this.sqlMapClient.queryForMap(SqlName.queryUserPhoneByManagerLCS,map,"uLoginName","uName");
	}

}
